@extends('backstage.layout.master')
@section('title', '更新启动蒙板')
@section('style')
        <!-- page specific plugin styles -->

<link rel="stylesheet" href="assets/css/jquery-ui-1.10.3.custom.min.css"/>
<link rel="stylesheet" href="assets/css/chosen.css"/>
<link rel="stylesheet" href="assets/css/datepicker.css"/>
<link rel="stylesheet" href="assets/css/bootstrap-timepicker.css"/>
<link rel="stylesheet" href="assets/css/daterangepicker.css"/>
<link rel="stylesheet" href="assets/css/colorpicker.css"/>

<!-- fonts -->

@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/prod-temp-creation-mask/creation-mask-list">创作类型蒙板列表</a>
            </li>
            <li>
                更新创作蒙板
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        创作类型蒙板
                        <small>
                            <i class="icon-double-angle-right"></i>
                            更新创作类型蒙板
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->

                        <form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
                            <div class="form-group {{$errors->first('name')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 名称 </label>

                                <div class="col-sm-4">
                                    <input type="text" name="name" value="{{isset($creation_mask->name)?$creation_mask->name:'' }}" id="form-field-1" placeholder="名称"
                                           class="width-100">
                                    <input type="hidden" name="id" value={{isset($creation_mask->id)?$creation_mask->id:0}}>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('name')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="col-md-offset-2 "  style="margin-left: 32%">
                                <img class="img-responsive" src="{{isset($creation_mask->original_image)?$creation_mask->original_image:''}}" width="100px"/>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('original_image')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
                                    Ico图片 </label>
                                <div class="col-sm-4">
                                    <input type="file"  name="original_image" placeholder="Ico图片">
                                </div>
                                <div class="col-sm-5">
                                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('original_image')}}</div>
                                </div>
                            </div>
                            <div class="form-group {{$errors->first('temp_category_id')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">产品模板类型</label>

                                <div class="col-sm-4">
                                    <input type="text" id="temp_category_name" value="{{isset($creation_mask->category_name)?$creation_mask->category_name:''}}" readonly placeholder="模板分类"
                                           class="width-100">
                                    <input type="hidden" name="temp_category_id" id="temp_category_id" value={{isset($creation_mask->product_temp_category_id)?$creation_mask->product_temp_category_id:0}}>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('temp_category_id')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group prod_temp_search">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">产品模板类型搜索</label>
                                <div class="col-xs-2">
                                    <input type="text"  value="" placeholder="产品模板类型关键字" class="width-100" id="search_temp_category_keyword">
                                </div>
                                <div class="col-sm-5">
                                    <input  type="button" value="搜索" class="button" id="temp_category_search">
                                    <select id="temp_category_search_res"  onchange="resultChange(this.options,this.options.selectedIndex)">
                                        @foreach($categorys as $category)
                                          <option @if($category->category_id==$creation_mask->product_temp_category_id)  selected @endif value={{isset($category->category_id)?$category->category_id:0}}>{{isset($category->name)?$category->name:''}}</option>
                                        @endforeach
                                    </select>
                                    <input type="button" value="+" class="button" onclick="addTempCategoryResource()" />
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('resource_id')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">跳转资源Id</label>

                                <div class="col-sm-4">
                                    <input type="text"  id="resource_name" readonly value="{{isset($creation_mask->product_temp_name)?$creation_mask->product_temp_name:0}}({{isset($creation_mask->product_temp_id)?$creation_mask->product_temp_id:0}})"
                                           class="width-100">
                                    <input type="hidden" name="resource_id" id="resource_id" value="{{isset($creation_mask->product_temp_id)?$creation_mask->product_temp_id:0}}" >
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('resource_id')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group prod_temp_search">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">跳转资源搜索</label>
                                <div class="col-xs-2">
                                    <input type="text"  value="" placeholder="模板关键字" class="width-100" id="search_keyword">
                                </div>
                                <div class="col-sm-5">
                                    <input  type="button" value="搜索" class="button" id="resource_search">
                                    <select id="search_temp_res"  onchange="resultChange(this.options,this.options.selectedIndex)"></select>
                                    <input type="button" value="+" class="button" onclick="addTempResource()" />
                                </div>
                            </div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="submit">
                                        <i class="icon-ok bigger-110"></i>
                                        保存
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset">
                                        <i class="icon-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>


                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $("#original_image ").ace_file_input({
                no_file: '还未选择图片',
                btn_choose: '选择',
                btn_change: '重新选择',
                droppable: false,
                onchange: null,
                thumbnail: true //| true | large
                //whitelist:'gif|png|jpg|jpeg'
                //blacklist:'exe|php'
                //onchange:''
                //
            });
            $('#resource_search').click(function () {
                var keyword=$("#search_keyword").val();
                keyword=trim(keyword);
                $.ajax({
                    type: "POST",
                    url: "/backstage/product-temp/search-temp",
                    data: {'search':keyword},
                    success: function (msg) {
                        if(msg.state=1){
                            var html='';
                            for(var a=0;a<msg['data'].length;a++) {
                                html+='<option value="' + msg['data'][a].product_temp_id + '">'+ msg['data'][a].name +'('+ msg['data'][a].product_temp_id +')</option><br />';
                            }
                            $("#search_temp_res").html(html);
                        }
                    }, error: function () {
                        swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
                    }
                });
            });
            $('#temp_category_search').click(function () {
                var keyword=$("#search_temp_category_keyword").val();
                keyword=trim(keyword);
                console.log('模板搜索关键字：'+keyword);
                $.ajax({
                    type: "POST",
                    url: "/backstage/product-temp/search-temp-category",
                    data: {'search':keyword},
                    success: function (msg) {
                        console.log('模板分类搜索结果');
                        console.log(msg['data']);
                        if(msg.state=1){
                            var html='';
                            for(var a=0;a<msg['data'].length;a++) {
                                html+='<option value="' + msg['data'][a].id + '">'+ msg['data'][a].name +'(Id:'+ msg['data'][a].id +')</option><br />';
                            }
                            $("#temp_category_search_res").html(html);
                        }
                    }, error: function () {
                        swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
                    }
                });
            });
        });
        function resultChange(options,index) {
            for(var i=0; i<options.length; i++){
                if(i==index){
                    options[i].selected = true;
                }else{
                    options[i].selected = false;
                }
            }
        }
        function addTempResource()
        {
            var selText=$("#search_temp_res option:selected").text();
            var selVal=$("#search_temp_res option:selected").val();
            if(!empty(selText)){
                $('#resource_name').val(selText);
            }
            if(!empty(selVal)){
                $('#resource_id').val(selVal);
            }
        }
        function addTempCategoryResource()
        {
            var selText=$("#temp_category_search_res option:selected").text();
            var selVal=$("#temp_category_search_res option:selected").val();
            if(!empty(selText)){
                $('#temp_category_name').val(selText);
            }
            if(!empty(selVal)){
                $('#temp_category_id').val(selVal);
            }
        }
        function trim(s){
            return s.replace(/(^\s*)|(\s*$)/g, "");
        }
        function empty(exp) {
            exp=trim(exp);
            if (!exp || typeof(exp)=="undefined" && exp=='')
            {
                return true;
            }
            return false;
        }
    </script>
@stop
